# 测试优化界面的简化版本
import tkinter as tk
from tkinter import ttk
from datetime import datetime

# 现代化主题配色
class ModernTheme:
    PRIMARY = "#2563EB"
    SUCCESS = "#10B981"
    WARNING = "#EF4444"
    INFO = "#06B6D4"
    BG_LIGHT = "#FFFFFF"
    BG_MEDIUM = "#F8FAFC"
    BG_DARK = "#1E293B"
    TEXT_DARK = "#0F172A"
    TEXT_LIGHT = "#FFFFFF"
    BORDER = "#E2E8F0"

def create_card(parent, bg_color=None, shadow=True):
    """创建现代卡片效果"""
    if bg_color is None:
        bg_color = ModernTheme.BG_LIGHT
    
    if shadow:
        shadow_frame = tk.Frame(parent, bg="#F1F5F9", bd=0)
        card = tk.Frame(shadow_frame, bg=bg_color, bd=1, relief="solid", highlightbackground=ModernTheme.BORDER)
        card.pack(padx=2, pady=2, fill=tk.BOTH, expand=True)
        return shadow_frame, card
    else:
        card = tk.Frame(parent, bg=bg_color, bd=1, relief="solid", highlightbackground=ModernTheme.BORDER)
        return card, card

def create_modern_button(parent, text, color_type="primary"):
    """创建现代化按钮"""
    colors = {
        "primary": (ModernTheme.PRIMARY, "#1D4ED8"),
        "success": (ModernTheme.SUCCESS, "#059669"),
        "warning": (ModernTheme.WARNING, "#DC2626"),
        "info": (ModernTheme.INFO, "#0891B2")
    }
    
    normal_color, hover_color = colors.get(color_type, colors["primary"])
    
    btn = tk.Button(parent, text=text, bg=normal_color, fg=ModernTheme.TEXT_LIGHT,
                   font=("Microsoft YaHei", 10, "bold"), bd=0, padx=20, pady=10,
                   cursor="hand2", relief="flat")
    
    def on_enter(e):
        btn.configure(bg=hover_color)
    def on_leave(e):
        btn.configure(bg=normal_color)
    
    btn.bind("<Enter>", on_enter)
    btn.bind("<Leave>", on_leave)
    
    return btn

def show_demo():
    """显示演示消息"""
    from tkinter import messagebox
    messagebox.showinfo("界面优化", "✅ 现代化界面设计已应用！\n\n特色功能：\n• 卡片式布局设计\n• 现代化配色方案\n• 悬停动画效果\n• 阴影和边框美化\n• 响应式布局")

# 创建主窗口
root = tk.Tk()
root.title("📊 界面优化预览")
root.geometry("1200x800")
root.configure(bg=ModernTheme.BG_MEDIUM)

# 顶部标题栏
title_frame = tk.Frame(root, bg=ModernTheme.PRIMARY, height=70)
title_frame.pack(fill=tk.X)
title_frame.pack_propagate(False)

title_label = tk.Label(title_frame, text="📊 应收账款统计系统 - 界面优化版",
                      bg=ModernTheme.PRIMARY, fg=ModernTheme.TEXT_LIGHT,
                      font=("Microsoft YaHei", 18, "bold"))
title_label.pack(expand=True)

# 主内容区域
main_frame = tk.Frame(root, bg=ModernTheme.BG_MEDIUM)
main_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)

# 左侧卡片 - 输入区域演示
left_shadow, left_card = create_card(main_frame)
left_shadow.grid(row=0, column=0, sticky="nsew", padx=(0, 10))

left_title = tk.Label(left_card, text="📝 订单录入区域", bg=ModernTheme.BG_LIGHT, 
                     fg=ModernTheme.PRIMARY, font=("Microsoft YaHei", 14, "bold"))
left_title.pack(pady=15)

# 输入框演示
input_frame = tk.Frame(left_card, bg=ModernTheme.BG_LIGHT)
input_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=20)

tk.Label(input_frame, text="📅 日期", bg=ModernTheme.BG_LIGHT, 
         fg=ModernTheme.TEXT_DARK, font=("Microsoft YaHei", 11, "bold")).pack(anchor="w", pady=(0, 5))
date_entry = tk.Entry(input_frame, font=("Microsoft YaHei", 11), bd=2, relief="solid")
date_entry.pack(fill=tk.X, pady=(0, 15))
date_entry.insert(0, datetime.now().strftime("%Y/%m/%d"))

tk.Label(input_frame, text="👤 客户名称", bg=ModernTheme.BG_LIGHT, 
         fg=ModernTheme.TEXT_DARK, font=("Microsoft YaHei", 11, "bold")).pack(anchor="w", pady=(0, 5))
customer_entry = tk.Entry(input_frame, font=("Microsoft YaHei", 11), bd=2, relief="solid")
customer_entry.pack(fill=tk.X, pady=(0, 15))
customer_entry.insert(0, "演示客户")

tk.Label(input_frame, text="💰 订单金额", bg=ModernTheme.BG_LIGHT, 
         fg=ModernTheme.TEXT_DARK, font=("Microsoft YaHei", 11, "bold")).pack(anchor="w", pady=(0, 5))
amount_entry = tk.Entry(input_frame, font=("Microsoft YaHei", 11), bd=2, relief="solid")
amount_entry.pack(fill=tk.X, pady=(0, 20))
amount_entry.insert(0, "100,000")

# 按钮演示
btn_frame = tk.Frame(input_frame, bg=ModernTheme.BG_LIGHT)
btn_frame.pack(fill=tk.X)

submit_btn = create_modern_button(btn_frame, "✅ 提交数据", "primary")
submit_btn.pack(fill=tk.X, pady=3)

edit_btn = create_modern_button(btn_frame, "✏️ 编辑选中", "info")
edit_btn.pack(fill=tk.X, pady=3)

delete_btn = create_modern_button(btn_frame, "🗑️ 删除选中", "warning")
delete_btn.pack(fill=tk.X, pady=3)

export_btn = create_modern_button(btn_frame, "📊 导出Excel", "success")
export_btn.pack(fill=tk.X, pady=3)

# 中间卡片 - 表格区域演示
middle_shadow, middle_card = create_card(main_frame)
middle_shadow.grid(row=0, column=1, sticky="nsew", padx=10)

middle_title = tk.Label(middle_card, text="📈 应收账款统计表", bg=ModernTheme.BG_LIGHT, 
                       fg=ModernTheme.PRIMARY, font=("Microsoft YaHei", 14, "bold"))
middle_title.pack(pady=15)

# 表格演示
table_frame = tk.Frame(middle_card, bg=ModernTheme.BG_LIGHT)
table_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=(0, 20))

# 创建简化的表格演示
columns = ("序号", "日期", "客户", "订单号", "金额")
tree = ttk.Treeview(table_frame, columns=columns, show="headings", height=15)

for col in columns:
    tree.heading(col, text=col)
    tree.column(col, width=100, anchor=tk.CENTER)

# 添加演示数据
demo_data = [
    (1, "2025/07/29", "客户A", "8001", "¥ 50,000"),
    (2, "2025/07/28", "客户B", "8002", "¥ 75,000"),
    (3, "2025/07/27", "客户C", "8003", "¥ 120,000"),
]

for data in demo_data:
    tree.insert("", "end", values=data)

tree.pack(fill=tk.BOTH, expand=True)

# 右侧卡片 - 统计区域演示
right_shadow, right_card = create_card(main_frame)
right_shadow.grid(row=0, column=2, sticky="nsew", padx=(10, 0))

right_title = tk.Label(right_card, text="📊 汇总统计", bg=ModernTheme.BG_LIGHT, 
                      fg=ModernTheme.PRIMARY, font=("Microsoft YaHei", 14, "bold"))
right_title.pack(pady=15)

stats_frame = tk.Frame(right_card, bg=ModernTheme.BG_LIGHT)
stats_frame.pack(fill=tk.BOTH, expand=True, padx=20, pady=(0, 20))

# 统计卡片演示
stat_cards = [
    ("订单总额", "¥ 245,000", ModernTheme.PRIMARY),
    ("已付总额", "¥ 180,000", ModernTheme.SUCCESS),
    ("未付总额", "¥ 65,000", ModernTheme.WARNING)
]

for title, value, color in stat_cards:
    card_shadow, card = create_card(stats_frame, color)
    card_shadow.pack(fill=tk.X, pady=5)
    
    tk.Label(card, text=title, bg=color, fg=ModernTheme.TEXT_LIGHT,
            font=("Microsoft YaHei", 10, "bold")).pack(pady=(8, 2))
    tk.Label(card, text=value, bg=color, fg=ModernTheme.TEXT_LIGHT,
            font=("Microsoft YaHei", 14, "bold")).pack(pady=(2, 8))

# 演示按钮
demo_btn = create_modern_button(stats_frame, "🎨 查看优化效果", "info")
demo_btn.configure(command=show_demo)
demo_btn.pack(fill=tk.X, pady=20)

# 配置网格权重
main_frame.grid_columnconfigure(0, weight=1)
main_frame.grid_columnconfigure(1, weight=2)
main_frame.grid_columnconfigure(2, weight=1)
main_frame.grid_rowconfigure(0, weight=1)

# 状态栏
status_frame = tk.Frame(root, bg=ModernTheme.BG_DARK, height=30)
status_frame.pack(fill=tk.X, side=tk.BOTTOM)
status_frame.pack_propagate(False)

status_label = tk.Label(status_frame, text="🎨 界面优化预览 - 现代化设计已应用",
                       bg=ModernTheme.BG_DARK, fg=ModernTheme.TEXT_LIGHT,
                       font=("Microsoft YaHei", 10))
status_label.pack(side=tk.LEFT, padx=15, pady=5)

version_label = tk.Label(status_frame, text="Preview v2.0",
                        bg=ModernTheme.BG_DARK, fg="#94A3B8",
                        font=("Arial", 9))
version_label.pack(side=tk.RIGHT, padx=15, pady=5)

print("🎨 界面优化预览已启动")
print("这是一个演示版本，展示了现代化的界面设计效果")

if __name__ == "__main__":
    root.mainloop()
